package com.bookstore.backend.config;

import com.bookstore.backend.exception.ServiceException;
import com.bookstore.backend.model.ResultVO;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author: world
 * @date: 2022/7/29 15:13
 * @description: 全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    // 全局捕获RuntimeException异常处理
    @ExceptionHandler(RuntimeException.class)
    public ResultVO<Object> runtimeException(RuntimeException runtimeException){
        return ResultVO.error(runtimeException.getMessage());
    }

    @ExceptionHandler(ServiceException.class)
    public ResultVO<Object> serviceException(ServiceException serviceException){
        return ResultVO.error(serviceException.getMessage());

    }
}
